package my.jwds.p744;

public class NextGreatestLetter {
    public static void main(String[] args) {
        NextGreatestLetter obj = new NextGreatestLetter();
    }


    public char nextGreatestLetter(char[] letters, char target) {
        Character maxToMin = null;
        char min = 'z';
        for (char letter : letters) {
            if (letter > target && (maxToMin == null || letter < maxToMin)){
                maxToMin = letter;
            }
            if (letter < min)min = letter;
        }
        if (maxToMin == null)maxToMin = min;
        return maxToMin;
    }
}